package com.cosina.game.crystallight.ui.mapselect;

import android.graphics.Bitmap;
import android.graphics.Point;
import android.widget.LinearLayout.LayoutParams;

import com.cosina.game.crystallight.CrystalLightActivity;
import com.cosina.game.crystallight.MediaPlayerAdapter;
import com.cosina.game.crystallight.ui.ResourceManager;
import com.cosina.game.crystallight.ui.ResourceReference;
import com.cosina.game.crystallight.ui.menu.CompositeView;
import com.cosina.game.crystallight.ui.menu.util.ViewPart;

public class DownPart extends CompositeView {

	private UpAndDownLayout parent;
	public DownPart(CrystalLightActivity activity, UpAndDownLayout upAndDownLayout) {
		super(activity);
		
		this.partXSpan = 0;
		this.partYSpan = UpAndDownLayout.UP_HEIGHT;
		
		this.parent = upAndDownLayout;
		this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, UpAndDownLayout.DOWN_HEIGHT));
		
		Bitmap statsImage = ResourceManager.get(ResourceReference.MAP_SELECT_STATS);
		Bitmap statsSelectedImage = ResourceManager.get(ResourceReference.MAP_SELECT_STATS_SELECTED);
		
		Bitmap skillImage = ResourceManager.get(ResourceReference.MAP_SELECT_SKILLS);
		Bitmap skillSelectedImage = ResourceManager.get(ResourceReference.MAP_SELECT_SKILLS_SELECTED);
		
		Bitmap highScoreImage = ResourceManager.get(ResourceReference.MAP_SELECT_HIGHSCORE);
		Bitmap highScoreSelectedImage = ResourceManager.get(ResourceReference.MAP_SELECT_HIGHSCORE_SELECTED);
		
		
		{
			Point leftTop = new Point(0,0);
			statsPart = new ViewPart(1, this, statsImage, leftTop);
		}
		{
			Point leftTop = new Point(0,0);
			statsSelectedPart = new ViewPart(-1, this, statsSelectedImage, leftTop);
		}
		{
			Point leftTop = new Point(108,0);
			skillPart = new ViewPart(2, this, skillImage, leftTop);
		}
		{
			Point leftTop = new Point(108,0);
			skillSelectedPart = new ViewPart(-2, this, skillSelectedImage, leftTop);
		}
		{
			Point leftTop = new Point(212,0);
			highScorePart = new ViewPart(3, this, highScoreImage, leftTop);
		}
		{
			Point leftTop = new Point(212,0);
			highScoreSelectedPart = new ViewPart(-3, this, highScoreSelectedImage, leftTop);
		}
		
		viewParts.add(statsPart);
		viewParts.add(skillPart);
		viewParts.add(highScorePart);
		
	}
	ViewPart statsPart, statsSelectedPart,
			 skillPart, skillSelectedPart,
			 highScorePart, highScoreSelectedPart;
	
	
	@Override
	public void onButtonClicked(int id) {
		MediaPlayerAdapter.mapButtonClick();
		switch (id) {
		case 1:
			viewParts.clear();
			viewParts.add(statsSelectedPart);
			viewParts.add(skillPart);
			viewParts.add(highScorePart);
			parent.showStats();
			return;
		case 2:
			viewParts.clear();
			viewParts.add(statsPart);
			viewParts.add(skillSelectedPart);
			viewParts.add(highScorePart);
			parent.showSkills();
			return;
		case 3:
			viewParts.clear();
			viewParts.add(statsPart);
			viewParts.add(skillPart);
			viewParts.add(highScoreSelectedPart);
			parent.showHighScore();
			return;
		case -1:
			viewParts.remove(statsSelectedPart);
			viewParts.add(statsPart);
			parent.showMap();
			return;
		case -2:
			viewParts.remove(skillSelectedPart);
			viewParts.add(skillPart);
			parent.showMap();
			return;
		case -3:
			viewParts.remove(highScoreSelectedPart);
			viewParts.add(highScorePart);
			parent.showMap();
			return;
		}
	}

}
